package vip.xiaonuo.hontu.util;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class TenletTest {
    public static boolean telnet(String hostname, int port, int timeout){
        Socket socket = new Socket();
        boolean isConnected = false;
        try {
            socket.connect(new InetSocketAddress(hostname, port), timeout); // 建立连接
            isConnected = socket.isConnected(); // 通过现有方法查看连通状态
        } catch (IOException e) {

        }finally{
            try {
                socket.close();   // 关闭连接
            } catch (IOException e) {
                System.out.println("false");
            }
        }
        return isConnected;
    }

    public static void main(String[] args) {
        for(int i = 1 ; i < 254 ; i++){
            String ip = "176.16.20." + i;
            if(telnet(ip , 80 , 300)){
                System.out.println("telnet "+ ip + " " + 80 + "==>isConnected");
            }
        }
    }
}
